package com.shenmazong.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shenmazong.pojo.TbTaskGrade;
import com.shenmazong.service.TbTaskGradeService;
import com.shenmazong.mapper.TbTaskGradeMapper;
import com.shenmazong.utils.ResultResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sun.java2d.loops.TransformBlit;

import java.util.Date;
import java.util.List;

/**
 *
 */
@Service
public class TbTaskGradeServiceImpl extends ServiceImpl<TbTaskGradeMapper, TbTaskGrade>
implements TbTaskGradeService{
    @Autowired
    TbTaskGradeMapper tbTaskGradeMapper;

    @Override
    public PageInfo findTbTaskGradeList(Integer pageNum, Integer pageSize, Object taskGrade) {
        PageHelper.startPage(pageNum,pageSize);
        List<TbTaskGrade> tbTaskGrades=tbTaskGradeMapper.findTbTaskGradeList(taskGrade);
        PageInfo<TbTaskGrade> pageInfo = new PageInfo<>(tbTaskGrades);
        return pageInfo;
    }

    @Override
    public ResultResponse saveTbTaskGrade(TbTaskGrade tbTaskGrade) {
        tbTaskGrade.setCreateTime(new Date());
        tbTaskGrade.setCreateTime(new Date());
        int insert = tbTaskGradeMapper.insert(tbTaskGrade);
        if(insert<0){
            return ResultResponse.FAILED(-1,"添加失败");
        }
        return ResultResponse.SUCCESS("添加成功");
    }

    @Override
    public ResultResponse echoTbTaskGrade(TbTaskGrade tbTaskGrade) {
        TbTaskGrade tbTaskGrade1 = tbTaskGradeMapper.selectById(tbTaskGrade.getGradeId());
        if(tbTaskGrade1==null){
            return ResultResponse.FAILED(-1,"回显失败");
        }
        return ResultResponse.SUCCESS(tbTaskGrade1);
    }

    @Override
    public ResultResponse updateTbTaskGrade(TbTaskGrade tbTaskGrade) {
        tbTaskGrade.setUpdateTime(new Date());
        int i = tbTaskGradeMapper.updateById(tbTaskGrade);
        if(i<0){
            return ResultResponse.FAILED(-1,"修改失败");
        }
        return ResultResponse.SUCCESS("修改成功");
    }

    @Override
    public ResultResponse delTbTaskGrade(TbTaskGrade tbTaskGrade) {
        tbTaskGradeMapper.deleteById(tbTaskGrade.getGradeId());
        return ResultResponse.SUCCESS("删除成功");
    }
}




